home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18031 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: druid.borland.com!usenet
  2. From: pete@borland.com (Pete Becker)
  3. Newsgroups: comp.os.ms-windows.programmer.tools.misc,comp.os.ms-windows.programmer.win32,comp.os.ms-windows.programmer.misc,comp.lang.c++
  4. Subject: Re: [Q] Why doesn't this compile?
  5. Date: 18 Apr 1996 16:19:39 GMT
  6. Organization: Borland International
  7. Message-ID: <4l5q2r$ktd@druid.borland.com>
  8. References: <317523C0.5042@eps.agfa.be> <4l3cpv$l74@helium.einet.net>
  9. NNTP-Posting-Host: pbecker.borland.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <4l3cpv$l74@helium.einet.net>, arisco@tradewave.com says...
  15. >
  16. >Ranko Orlic <rorlic@eps.agfa.be> wrote:
  17. >
  18. >>Using MSVC 4.0 compiler I get the following:
  19. >
  20. >>File test.cpp: ---------------------------------
  21. >
  22. >>class A {
  23. >>public:
  24. >>       class L {
  25. >>       public:
  26. >>               L() {}
  27. >>               virtual void f() {
  28. >>                       int dummy = 0;
  29. >>               }
  30. >>       };
  31. >>       A();
  32. >>};
  33. >
  34. >>class B : public A {
  35. >>       class L : public A::L {
  36. >>       public:
  37. >>               L() {}
  38. >>               virtual void f() {
  39. >>                       A::L::f();
  40. >>               }
  41. >>       };
  42. >>       B();
  43. >>};
  44. >
  45. >>Compilation result: ----------------------------
  46. >
  47. >>test.cpp(18) : error C2352: 'A::L::f' : illegal call of 
  48. >>nonstatic member function
  49. >>Error executing cl.exe.
  50. >>test.obj - 1 error(s), 1 warning(s)
  51. >
  52. >>------------------------------------------------
  53. >
  54. >>Anybody knows what's wrong with it?
  55. >>Thanks,
  56. >
  57. >>-- Ranko.
  58. >
  59. >You cannot call a non-static member function without specifying
  60. >an object.  The way you've written this, there is no way for B::L::f()
  61. >to set its "this" pointer.  Of course, if this is really what you want
  62. >
  63. >to do, the declaration of B::L::f() is unnecessary, since B::L
  64. > inherits the A::L::f() virtual method from its base class.
  65.  
  66. Huh? The call is perfectly legal, and the scope qualifier is necessary. The 
  67. nesting makes things look more complicated, but this is nothimg more than a 
  68. virtual function calling the corresponding function in the base class. The name 
  69. of that base class is A::L, which is why things look a little nasty.
  70.  
  71.